package org.innovasix.educational.javap.domain.datatypes;

import org.innovasix.educational.javap.exception.InvalidArgumentException;

/**
 * Unsigned integer made up of 2 bytes
 * Range: From 0 to 65,535 which equals 2^16 - 1
 * 
 * @author sven.mentl@gmail.com
 *
 */
public class u2 {

	private int value;
	
	public u2(int highByte, int lowByte){
		if(lowByte < 0 ||lowByte > 255) throw new InvalidArgumentException("lowByte " + lowByte + " is out of range.");
		if(highByte < 0 ||highByte > 255) throw new InvalidArgumentException("highByte " + highByte + " is out of range.");
		this.value = (highByte << 8) + lowByte;
	}
	
	public int getValue() {
		return value;
	}
	
	public String toString(){
		return "0x" + LeadingZerosPadder.pad(4, value);
	}
}
